<template>
  <div>
    <!-- 顶部滑动条 -->
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
      >
        <div class="mui-scroll">
          <a
            :class="['mui-control-item',item.id===0?'mui-active':'']"
            v-for="item in cates"
            :key="item.id" @tap="getPhotoListById()"
          >{{item.title}}</a>
        </div>
      </div>
    </div>
    <!-- 图片列表 -->
    <ul class="photo-list">
      <router-link v-for="item in imgs" :key="item.id" 
      :to="'/home/photoinfo/'+item.id" tag="li">
        <img v-lazy="item.pic">
        <div class="info">
          <h1 class="info-title">{{item.title}}</h1>
          <div class="info-body">{{item.content}}</div>
        </div>
      </router-link>
    </ul>
  </div>
</template>

<script>
import mui from "../../lib/mui.min.js";
import "../../../aaa_lianxi/mock_photo.js";

export default {
  data() {
    return {
      cates: [],
      imgs: []
    };
  },
  created() {
    this.getAllCategory();
    this.getPhotoListById();
  },
  mounted() {
    //组件渲染完事之后会
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  },
  methods: {
    // 获取分类
    getAllCategory() {
      this.$http.get("../../../static/title.json").then(res => {
        // console.log(res);
        res.body.cates.unshift({ id: 0, title: "全部" });
        this.cates = res.body.cates;
      });
    },
    // 获取图片  这里应该是通过id来的
    getPhotoListById() {
      this.$http.get("/news/photo").then(res => {
        // console.log(res);
        this.imgs = res.body.photos;
      });
    }
  }
};
</script>

<style lang="scss" scoped>

* {
  touch-action: pan-y;
}
.photo-list {
  list-style-type: none;
  margin: 0;
  padding: 10px;
  margin-bottom: 0px;

  li {
    background-color: #ccc;
    text-align: center;
    margin-bottom: 10px;
    position: relative;
    img {
      width: 100%;
      height: 100%;
      vertical-align: middle;
    }
    img[lazy="loading"] {
      width: 40px;
      height: 300px;
      margin: auto;
    }
    .info {
      color: white;
      text-align: left;
      position: absolute;
      bottom: 0;
      background-color: rgba(0,0,0,0.4);
      max-height: 84px;
      .info-title {
        font-size: 14px;
      }
      .info-body {
        font-size: 13px;
      }
    }
  }
}
</style>
